const AutoImport = require("unplugin-auto-import/webpack");
const Components = require("unplugin-vue-components/webpack");
const { ElementPlusResolver } = require("unplugin-vue-components/resolvers");
const path = require("path");
function resolve(dir) {
  return path.join(__dirname, dir); //path.join(__dirname)设置绝对路径
}
module.exports = {
  lintOnSave: false,
  css: {
    loaderOptions: {
      sass: {
        additionalData: `@use "@/styles/element/index.scss" as *;`,
      },
    },
  },
  configureWebpack: {
    plugins: [
      AutoImport.default({
        imports: ["vue", "vue-router"],
        resolvers: [ElementPlusResolver()],
      }),
      Components.default({
        dirs: ["src/components/"],
        resolvers: [ElementPlusResolver({ importStyle: "sass" })],
      }),
    ],
  },
  chainWebpack: (config) => {
    config
      .plugin("html")
      .tap((args) => {
        args[0].title = process.env.VUE_APP_TITLE;
        return args;
      })
      .end()
      .resolve.alias.set("@", resolve("./src"))
      .end();
    // 删除console、debugger、注释
    config.optimization.minimizer("terser").tap((args) => {
      const { terserOptions } = args[0];
      Object.assign(terserOptions, {
        compress: {
          ...terserOptions.compress,
          drop_console: true,
          drop_debugger: true,
        },
      });
      return args;
    });
  },
  publicPath: "./",
  devServer: {
    host: "0.0.0.0",
    proxy: {
      "/api": {
        target: "https://jxkjzylib.nccloudmedia.com/libsp",
        pathRewrite: { "^/api": "" },
        changeOrigin: true,
        secure: true, // 若代理的地址是https协议，需要配置这个属性
      },
    },
  },
};
